//
//  OTNavgationController.m
//  OT_OC
//
//  Created by yunmian on 2019/7/15.
//  Copyright © 2019 James. All rights reserved.
//

#import "OTNavgationController.h"

@interface OTNavgationController ()<UINavigationControllerDelegate,UIGestureRecognizerDelegate>

@end

@implementation OTNavgationController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    __weak OTNavgationController *weakSelf = self;
    if ([self respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
        self.interactivePopGestureRecognizer.delegate = weakSelf;
        self.delegate = weakSelf;
    }
}

- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated
{
    if (self.childViewControllers.count > 0) {
        viewController.hidesBottomBarWhenPushed = YES;
    }
    [super pushViewController:viewController animated:animated];
}

- (void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated {
    NSArray *ctrlArray = navigationController.viewControllers;
    if (ctrlArray.count > 1) {
        if ([self respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
            self.interactivePopGestureRecognizer.enabled = YES;
        }
    }else {
        if ([self respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
            self.interactivePopGestureRecognizer.enabled = NO;
        }
    }
}

@end
